<?php

namespace Action\Flow\GenericFlow\Comment;

class Add extends \Library\Action\UserAction 
	implements \Library\Action\AjaxAction {

	private $_comment;
	private $_wall;
	private $_post;

	public function execute() {
		parent::execute();
		
		$item_id = $this->getParam( 'id' );
		$this->_post = \Bean\Flow\GenericFlow\Item::get( $item_id );
		$message = trim( $this->getParam( 'message' ) );

		_a( $this->_post->isCommentable(), 'This post is not commentable' );
		_a( $message ? true : false, 'Message musn\'t be empty' );
		
		$this->_comment = $this->_post->addComment( $message );
	}
	
	public function getComment() {
		return $this->_comment;
	}

}
